﻿<%@ Page Title="" Language="C#" MasterPageFile="~/master_form.master" AutoEventWireup="true" CodeFile="phan_quyen.aspx.cs" Inherits="App_Form_Phan_quyen_phan_quyen" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <script type="text/javascript" src="../js/plugin/CellEditing.js"></script>
    <script type="text/javascript" src="../../js/plugin/CheckColumn.js"></script>

    <link rel="stylesheet" type="text/css" href="../../shared/css/CheckHeader.css" />

    <script type="text/javascript">

        function P_DATA() {

            //./DanhMuc/chom_phongban.aspx


            // if(a.toUpperCase()!='ADMIN') return alert("Bạn không có quyền thực hiện chức năng này");
            Ext.Loader.setConfig({
                enabled: true
            });
            Ext.Loader.setPath('Ext.ux', '../ux');

            Ext.require([
            'Ext.selection.CellModel',
            'Ext.window.*',
            'Ext.grid.*',
            'Ext.data.*',
            'Ext.util.*',
            'Ext.state.*',
            'Ext.form.*',
            'Ext.ux.CheckColumn'
            ]);

            Ext.onReady(function () {

                Ext.QuickTips.init();


                var bd = Ext.getBody();

                var gridForm = Ext.create('Ext.form.Panel', {
                    id: 'formmain',
                    frame: true,
                    bodyPadding: 5,
                    layout: {
                        type: 'table',
                        columns: 2
                    },
                    fieldDefaults: {
                        labelAlign: 'left',
                        msgTarget: 'side'
                    },

                    items: [
                        {
                            margin: '0 0 5 5',
                            xtype: 'fieldset',
                            title: 'Thông tin người sử dụng',
                            defaults: {
                                width: 450,
                                heigth: 400,
                                labelWidth: 90
                            },
                            defaultType: 'textfield',
                            items: [
                                {
                                    fieldLabel: 'Tên đăng nhập',
                                    id: 'userName',
                                    name: 'userName'
                                },
                                 {
                                     fieldLabel: 'Tên đăng nhập',
                                     id: 'Id',
                                     hidden: true,
                                     name: 'id'
                                 },
                                 {
                                     fieldLabel: 'Mật khẩu',
                                     id: 'pass',
                                     inputType: 'password',
                                     name: 'pass'
                                 },
                                 {

                                     xtype: 'fieldcontainer',
                                     combineErrors: true,
                                     layout:
                                         {
                                             type: 'hbox',
                                             defaultMargins: { top: 0, right: 5, bottom: 0, left: 0 }
                                         },
                                     items:
                                     [
                                         { xtype: 'displayfield', width: 90, fieldLabel: 'Phòng' },
                                         { xtype: 'displayfield', width: 90, fieldLabel: '', id: 'id_ph', hidden: true },
                                         {
                                             xtype: 'textfield',
                                             width: 320,
                                             id: 'ten_ph',
                                             name: 'ten_ph'
                                         },
                                         {
                                             xtype: 'button', width: 30, text: '...', icon: '',
                                             handler: function () {
                                                 var panel = new Ext.Window({
                                                     title: 'Static Panel',
                                                     width: 400,
                                                     height: 600,
                                                     bbar: [
                                                      {
                                                          text: 'Chọn',
                                                          handler: function () {
                                                              win.close();
                                                          }
                                                      }
                                                     ],
                                                     frame: true,
                                                     html: '<iframe id="upload" frameborder="0" src="../DanhMuc/chon_ns.aspx?id_ph=' + Ext.getCmp("id_ph").getValue() + '" width="100%" height="100%" />'
                                                 });
                                                 panel.show();
                                                 //Mo file
                                                 //var a = $("#loai").contents().find("#conten").html();
                                                 //var win = Ext.create('Ext.window.Window', {
                                                 //    autoShow: true,
                                                 //    title: 'Chọn phòng ban', width: 430, height: 400,
                                                 //    html: String.format('<iframe id="upload" frameborder="0" src="../DanhMuc/chon_ns.aspx?id_ph=' + Ext.getCmp("id_ph").getValue() + '" width="100%" height="100%" />'),
                                                 //    listeners: {
                                                 //        close: function () {
                                                 //            var q = $("#upload").contents().find("#ndung").html();
                                                 //            if (q == "") return;
                                                 //            var a_gtri = q.split('#');
                                                 //            Ext.getCmp("ten_phong").setValue(a_gtri[1]);
                                                 //            Ext.getCmp("id_ph").setValue(a_gtri[0]);
                                                 //            Ext.getCmp("Ten").focus();
                                                 //        }
                                                 //    },
                                                 //    bbar: [
                                                 //     {
                                                 //         text: 'Close',
                                                 //         handler: function () { this.up('.window').close(); }
                                                 //     }
                                                 //    ]
                                                 //});

                                                 //win.show();
                                                 //win.center();

                                             }
                                         }
                                     ]
                                 },
                                  {

                                      xtype: 'fieldcontainer',
                                      combineErrors: true,
                                      layout:
                                          {
                                              type: 'hbox',
                                              defaultMargins: { top: 0, right: 5, bottom: 0, left: 0 }
                                          },
                                      items:
                                      [
                                          { xtype: 'displayfield', width: 90, fieldLabel: 'Tên' },
                                          { xtype: 'displayfield', width: 90, fieldLabel: '', id: 'id_ns', hidden: true },
                                          {
                                              xtype: 'textfield',
                                              width: 320,
                                              id: 'Ten',
                                              name: 'Ten'
                                          },
                                          {
                                              xtype: 'button', width: 30, text: '...', icon: '',
                                              handler: function () {
                                                  //Mo file
                                                  var win = new Ext.create("Ext.window.Window", {
                                                      title: 'Chọn nhân sự', width: 430, height: 400, plain: true,
                                                      autoLoad: {
                                                          url: '../DanhMuc/chon_ns.aspxid_ph=' + Ext.getCmp("id_ph").getValue()
                                                      },
                                                      // el: String.format('<iframe id="upload" frameborder="0" src="../DanhMuc/chon_ns.aspx?id_ph=' + Ext.getCmp("id_ph").getValue() + '" width="100%" height="100%" />'),
                                                      listeners: {
                                                          close: function () {
                                                              //var q = $("#upload").contents().find("#ndung").html();
                                                              //if (q == "") return;
                                                              //var a_gtri = q.split('#');
                                                              //Ext.getCmp("Ten").setValue(a_gtri[1]);
                                                              //Ext.getCmp("id_ns").setValue(a_gtri[0]);
                                                              //Ext.getCmp("Dia_chi").focus();
                                                          }
                                                      },
                                                      buttons: [
                                                      {
                                                          text: 'Chọn',
                                                          handler: function () {
                                                              win.close();
                                                          }
                                                      }
                                                      ]
                                                  });
                                                  // win.ur
                                                  win.show(this);
                                                  win.center();
                                              }
                                          }
                                      ]
                                  },
                                  {
                                      fieldLabel: 'Địa chỉ',
                                      id: 'Dia_chi',
                                      name: 'Dia_chi'
                                  },
                                  {
                                      fieldLabel: 'Email',
                                      id: 'email',
                                      name: 'email'
                                  }
                            ]
                        },
                           {
                               margin: '0 0 5 5',
                               xtype: 'fieldset',
                               rowspan: 2,
                               title: 'Thông tin NSD',
                               defaults: {
                                   width: 400,
                                   heigth: 500,
                                   labelWidth: 90
                               },
                               items: [
                                   {
                                       xtype: 'gridpanel',
                                       id: 'nsd',
                                       heigth: 500,
                                       store: null,
                                       columns: [
                                           { header: 'Id', hidden: true, dataIndex: 'id' },
                                            { header: 'dc', hidden: true, dataIndex: 'Dia_chi' },
                                           { header: 'a', hidden: true, dataIndex: 'id_ns' },
                                            { header: 'b', hidden: true, dataIndex: 'email' },
                                           { header: 'Tên đăng nhập', width: 100, flex: 1, dataIndex: 'userName' },
                                           { header: 'Tên', width: 200, flex: 1, dataIndex: 'Ten' }
                                       ],
                                       listeners: {
                                           selectionchange: function (model, records) {
                                               if (records[0]) {
                                                   this.up('form').getForm().loadRecord(records[0]);
                                                   var id_nsd = records[0].get('id');
                                                   wdkhp.Fs_PHAN_QUYEN_CT(id_nsd, P_LOAD_CT, P_LOI_CSDL, P_LOI_TGIAN);
                                               }
                                           }
                                       }
                                   }
                               ]
                           },
                              {
                                  margin: '0 0 5 5',
                                  xtype: 'fieldset',
                                  title: 'Thông tin chính',
                                  defaults: {
                                      width: 290,
                                      heigth: 300,
                                      labelWidth: 90
                                  },
                                  defaultType: 'textfield',
                                  items: [
                                       {
                                           xtype: 'grid',
                                           id: 'modunHT',
                                           width: 480,
                                           store: null,
                                           plugins: Ext.create('Ext.grid.plugin.CellEditing', {
                                               clicksToEdit: 1
                                           }),
                                           columns: [
                                               { header: 'Id1', hidden: true, dataIndex: 'Id_modun' },
                                               { header: 'Tên Modun', width: 150, flex: 1, dataIndex: 'mondun' },
                                               {
                                                   header: 'Thêm',
                                                   dataIndex: 'Them',
                                                   width: 55,
                                                   xtype: 'checkcolumn', cls: 'x-grid-checkheader-editor'
                                               },
                                                 {
                                                     header: 'Xóa',
                                                     dataIndex: 'Xoa',
                                                     width: 55,
                                                     xtype: 'checkcolumn', cls: 'x-grid-checkheader-editor'
                                                 },
                                                  {
                                                      header: 'Xem',
                                                      dataIndex: 'Xem',
                                                      width: 55,
                                                      xtype: 'checkcolumn', cls: 'x-grid-checkheader-editor'
                                                  }
                                           ]
                                       }
                                  ]
                              },
                            {
                                margin: '0 0 5 5',
                                padding: '3 0 3 250',
                                xtype: 'fieldset',
                                title: '',
                                colspan: 2,
                                defaults: {
                                    width: 500,
                                    heigth: 250,
                                    labelWidth: 90
                                },
                                items: [
                                    {
                                        name: 'add',
                                        xtype: 'button',
                                        width: 90,
                                        icon: '../../shared/icons/fam/add.gif',
                                        text: 'Thêm mới',
                                        handler: function () {
                                            var b_userName = Ext.getCmp("userName").getValue(),
                                                b_id_user = Ext.getCmp("Id").getValue(), b_id_ns = Ext.getCmp("id_ns").getValue(),
                                                b_ten = Ext.getCmp("Ten").getValue(),
                                                b_pass = Ext.getCmp("pass").getValue(),
                                                b_dc = Ext.getCmp("Dia_chi").getValue(), b_email = Ext.getCmp("email").getValue(),
                                                b_phong_id = Ext.getCmp("id_ph").getValue(),
                                                b_noi_nhan = Ext.getCmp("ten_phong").getValue();
                                            if (b_userName == "") return alert("Chưa nhập tên đăng nhập");
                                            if (b_pass == "") return alert("Chưa nhập password");
                                            if (b_phong_id == "") return alert("Chưa chọn phòng");
                                            if (b_id_ns == "") return alert("Chưa chọn tên");
                                            if (b_email == "") return alert("Chưa nhập email");
                                            ////Goi service  
                                            var b_tinhdiem = Ext.getCmp('modunHT');
                                            var a_gtriGrid = new Array();
                                            var i = 0;
                                            b_tinhdiem.getStore().each(function (record) {
                                                a_gtriGrid[i] = [record.get("Id_modun"), record.get("mondun"), record.get("Xem"), record.get("Them")
                                                     , record.get("Xoa")];
                                                i++;
                                            });
                                            wdkhp.Fs_PHAN_QUYEN_THEM(b_id_user, b_userName, b_pass, b_id_ns, b_ten, b_dc, b_email, b_phong_id, b_noi_nhan, a_gtriGrid, P_LOAD_TTCHUNG, P_LOI_CSDL, P_LOI_TGIAN);
                                        }
                                    },
                                    {
                                        name: 'moi',
                                        xtype: 'button',
                                        width: 90,
                                        icon: '../../shared/icons/fam/refesh.png',
                                        text: 'Mới',
                                        handler: function () {
                                            this.up('form').getForm().reset();

                                            var b_tinhdiem = Ext.getCmp('modunHT');
                                            b_tinhdiem.getStore().each(function (record) {
                                                record.set("Xem", false);
                                                record.set("Them", false);
                                                record.set("Xoa", false);
                                            });
                                        }
                                    },
                                    {
                                        name: 'xoa',
                                        xtype: 'button',
                                        width: 90,
                                        icon: '../../shared/icons/fam/delete.gif',
                                        text: 'Xóa',
                                        handler: function () {
                                            var ch = confirm("Bạn có chắc chắn xóa ?");
                                            if (ch) {
                                                var b_id = Ext.getCmp("Id").getValue();
                                                if (b_id == "") return alert("Chưa chọn người sử dụng để xóa");
                                                wdkhp.Fs_PHAN_QUYEN_XOA(b_id, P_LOAD_TTCHUNG, P_LOI_CSDL, P_LOI_TGIAN);
                                            }
                                        }
                                    }
                                ]
                            }
                    ],
                    renderTo: bd
                })
                wdkhp.Fs_PHAN_QUYEN_TTCH(P_LOAD_TTCHUNG, P_LOI_CSDL, P_LOI_TGIAN);
            });

        }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <script type="text/javascript">
        function P_LOAD_TTCHUNG(b_kq) {
            if (Fb_LOI_KTRA(b_kq)) {
                form_P_LOI(b_kq);
                return;
            }
            else {
                var a_kq = b_kq.split('@');
                //debugger;
                var b_chuoi1 = CH_JSON(a_kq[0]),
                    b_chuoi2 = CH_JSON(a_kq[1]);
                //b_chuoi1[0< bSua
                for (var i = 0; i < b_chuoi1.length; i++) {
                    if (b_chuoi1[i].Xem == "F")
                        b_chuoi1[i].Xem = false;
                    else
                        b_chuoi1[i].Xem = true;
                    if (b_chuoi1[i].Xoa == "F")
                        b_chuoi1[i].Xoa = false;
                    else
                        b_chuoi1[i].Xoa = true;

                    if (b_chuoi1[i].Them == "F")
                        b_chuoi1[i].Them = false;
                    else
                        b_chuoi1[i].Them = true;

                }
                var a_data = Ext.create('Ext.data.Store', {
                    fields: ['Id_modun', 'mondun', 'Xem', 'Sua', 'Xoa', 'Them'],
                    data: b_chuoi1
                });

                var a = Ext.getCmp('modunHT');
                a.bindStore(a_data);

                var a_data1 = Ext.create('Ext.data.Store', {
                    fields: ['id', 'userName', 'Ten', 'Dia_chi', 'id_ns', 'id_ph', 'ten_ph', 'Dia_chi', 'email'],
                    data: b_chuoi2
                });

                var a = Ext.getCmp('nsd');
                a.bindStore(a_data1);
                Ext.getCmp('Id').setValue("");
            }
        }
        function P_LOAD_CT(b_kq) {
            if (Fb_LOI_KTRA(b_kq)) {
                form_P_LOI(b_kq);
                return;
            }
            var b_chuoi1 = CH_JSON(b_kq);

            for (var i = 0; i < b_chuoi1.length; i++) {
                if (b_chuoi1[i].Xem == "F")
                    b_chuoi1[i].Xem = false;
                else
                    b_chuoi1[i].Xem = true;
                if (b_chuoi1[i].Xoa == "F")
                    b_chuoi1[i].Xoa = false;
                else
                    b_chuoi1[i].Xoa = true;

                if (b_chuoi1[i].Them == "F")
                    b_chuoi1[i].Them = false;
                else
                    b_chuoi1[i].Them = true;

            }
            var a_data = Ext.create('Ext.data.Store', {
                fields: ['Id_modun', 'mondun', 'Xem', 'Sua', 'Xoa', 'Them'],
                data: b_chuoi1
            });

            var a = Ext.getCmp('modunHT');
            a.bindStore(a_data);
        }
    </script>
</asp:Content>

